import { createRouter, createWebHistory, VueRouter } from 'vue-router'
import Home from '../views/Home.vue'
const routes = [
  {
    path: '/',
    name: 'home',
    component: Home,
    children: [
      // 首页
      {
        path: '/',
        name: 'home',
        component: () => import('../components/G_main.vue'),
        // 独享守卫
        beforeEnter: (to, from, next) => {
          let isLogin = localStorage.getItem('isLogin');
          console.log(isLogin)
          if (isLogin == 1) {
            next();
          } else {
            next('/login');
          }
        }
      },
      // 课程管理
      {
        path: 'classCoure',
        name: 'classCoure',
        component: () => import('../components/G_classCoure.vue')
      },
      // 添加课程
      {
        path: 'addClassCoure',
        name: 'addClassCoure',
        component: () => import('../components/G_addClassCourse.vue')
      },
      // 订单
      {
        path: 'indent',
        name: 'indent',
        component: () => import('../components/Z-indent.vue')
      },
      // 退款
      {
        path: 'refund',
        name: 'refund',
        component: () => import('../components/Z-refund.vue')
      },
      // 学员
      {
        path: 'student',
        name: 'student',
        component: () => import('../components/Z-student.vue')
      },
      // 添加学员
      {
        path: 'addstudent',
        name: 'addstudent',
        component: () => import('../components/Z-add-student.vue')
      },

      // 讲师
      {
        path: 'lecturer',
        name: 'lecturer',
        component: () => import('../components/Z-lecturer.vue'),
      },
      // 添加讲师
      {
        path: 'addlecturer',
        name: 'addlecturer',
        component: () => import('../components/Z-add-course.vue'),
      },

      // 轮播
      {
        path: 'carousel',
        name: 'carousel',
        component: () => import('../components/Z-carousel.vue'),
      },
      // 添加轮播
      {
        path: 'addcarousel',
        name: 'addcarousel',
        component: () => import('../components/Z-add-carousel.vue'),
      },
      // 文章
      {
        path: 'article',
        name: 'article',
        component: () => import('../components/Z-article.vue'),
      },
      // 添加文章
      {
        path: 'addarticle',
        name: 'addarticle',
        component: () => import('../components/Z-add-article.vue'),
      },

      // 秒杀活动
      {
        path: 'kill',
        name: 'kill',
        component: () => import('../components/X-kill.vue')
      },
      // 添加秒杀活动
      {
        path: 'addKill',
        name: 'addKill',
        component: () => import('../components/X-add-kill.vue')
      },
      // 课程设置
      {
        path: 'courseSet',
        name: 'courseSet',
        component: () => import('../components/X-courseSet.vue')
      },

      // 优惠卷
      {
        path: 'coupon',
        name: 'coupon',
        component: () => import('../components/X-coupon.vue')
      },
      // 添加优惠卷
      {
        path: 'addCoupon',
        name: 'addCoupon',
        component: () => import('../components/X-add Coupons.vue')
      },
    ]
  },
  // 登录
  {
    path: '/login',
    name: 'login',
    component: () => import('../components/Login.vue')
  },
  // 注册
  {
    path: '/register',
    name: 'register',
    component: () => import('../components/Register.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

export default router
